package cn.hsw.component.auth.controller;

import cn.hsw.component.auth.constant.AuthConstant;
import cn.hsw.component.auth.service.AuthService;
import cn.hsw.component.core.dto.ResultDto;
import cn.hsw.component.core.util.ResultUtil;
import cn.hsw.component.web.validated.annotations.Phone;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotEmpty;

/**
 * 鉴权模块 所有登录功能皆在此处
 * @author 李子木
 */
@RestController
@RequestMapping(AuthConstant.PATH_PREFIX)
@Api(tags = "鉴权模块")
public class AuthController {

    @Autowired
    AuthService service;

    @ApiOperation("用户名密码登录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone", value = "手机号", required = true, paramType = "query",
                    dataTypeClass = String.class),
            @ApiImplicitParam(name = "password", value = "密码", required = true, paramType = "query",
                    dataTypeClass = String.class) })
    @PostMapping("/password")
    public ResultDto<String> loginByPassword(@Phone String phone, @NotEmpty(message = "密码不能为空") String password) {
        return ResultUtil.success(service.loginByPassword(phone, password));
    }
}
